package app.common;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Util {
    public static boolean hasValue(String str) {
        return (str != null && str.trim().length() > 0);
    }

    public static boolean hasValue(Object obj) {
        return (obj != null && obj.toString().trim().length() > 0);
    }

    public static Number toFixedDigitsFloat(Float f, int fixed) {
        double m = Math.pow(10, fixed);
        return Math.floor(f * m + 0.5) / m;
    }

    public static String toDefaultDateFormat(Date date) {
        String str = "";
        if (date != null) {
            DateFormat df = getDefaultDateFormat();
            str = df.format(date);
        }
        return str;
    }

    public static DateFormat getDefaultDateFormat() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df;
    }

    public static void main(String[] args) {
        System.out.println(toFixedDigitsFloat(2.236F, 2));
    }
}
